<?php 
	$this->load->view('header');
	$this->load->view('header_end');
	$this->load->view('part_view/mod_banner_header'); 
?>
<div id="block_menu_banner">
	<?php 
		$this->load->view('part_view/mod_menu_top'); 
	?>
</div>
<div id="content_block">
	<div id="left_column">
		<?php 
			$this->load->view('part_view/mod_check_search'); 
		?>
	</div>
	<div id="main_column">
		<h3 class="title_page">Chi tiết giỏ hàng</h3>
		<div id="cart_detail">
		<form id="frmCart" action="<?php echo base_url().'index.php/cart/update_cart' ?>" method="post">
			<table width="100%" id="tbl_cart_detail" cellpadding="0" cellspacing="1" class="tbl_cart_detail">
				<thead>
					<tr>
						<th style="width:60px;">Loại bỏ</th>
						<th style="width:60px;">Mã SP</th>
						<th>Sản phẩm</th>
						<th style="width:80px;">Số lượng</th>
						<th style="width:100px;">Đơn giá</th>
						<th style="width:100px;">Thành tiền</th>
					</tr>
				</thead>
				<tbody>
					<?php
						$count = 0;$total = 0;
						if(isset($_SESSION['cart'])):
						foreach($_SESSION['cart'] as $key=>$value): 
						$data	= get_product_byid($key);
						if($data['fprice_sale'] != 0 && $data['fprice_sale'] != '')
							$total += $_SESSION['cart'][$key] * $data['fprice_sale'];
						else
							$total += $_SESSION['cart'][$key] * $data['fprice'];
					?>
					<tr class="row<?php echo $count%2 ?>">
						<td class="delete"><a href="<?php echo base_url().'index.php/cart/delete_cart/'.$data['nid'] ?>"><img src="<?php echo base_url().'images/b_drop.png' ?>" alt="xoa sp" style="vertical-align:middle;"/></a></td>
						<td><?php echo $data['ccode'] ?></td>
						<td><?php echo $data['cproducts'] ?></td>
						<td><input type="text" name="quantity[]" value="<?php echo $_SESSION['cart'][$key] ?>" style="width:50px;text-align:center;"/></td>
						<td style="text-align:right;padding-right:5px;">
							<?php 
								if($data['fprice_sale'] != 0 && $data['fprice_sale'] != '')
									echo show_price($data['fprice_sale']).show_price_sale($data['fprice']);
								else
									echo show_price($data['fprice']);
							?>
						</td>
						<td style="text-align:right;padding-right:5px;">
							<?php 
								if($data['fprice_sale'] != 0 && $data['fprice_sale'] != '')
									echo number_format($_SESSION['cart'][$key]*$data['fprice_sale']).' VNĐ';
								else
									echo number_format($_SESSION['cart'][$key]*$data['fprice']).' VNĐ';
							?>
						</td>
					</tr>
					<input type="hidden" name="nid[]" value="<?php echo $data['nid'] ?>" />
					<?php 
						$count++;
						endforeach; 
						endif;
					?>
					<tr class="row1">
						<td colspan="5" style="text-align:right;font-weight:bold;">Tổng cộng: </td>
						<td style="font-weight:bold;text-align:right;padding-right:5px;"><?php echo number_format($total).' VNĐ' ?></td>
					</tr>
				</tbody>
			</table>
			
			<div style="margin:10px 0 10px 0;">
				<p style="color:#FF0000"><?php echo $message ?></p>
				<a href="<?php echo base_url().'index.php/cart/update_cart'?>" onclick='javascript: update_cart()'><img src="<?php echo base_url().'images/capnhatgiohang.gif' ?>" alt="cap nhat" style="vertical-align:middle;"/></a>
				
				<?php 
					$url = '';
					if(isset($_SESSION['back_link']))
						$url = $_SESSION['back_link'];
					else
						$url = base_url();
				?>
				<a href="<?php echo $url ?>"><img src="<?php echo base_url().'images/tieptucmua.gif' ?>" alt="tiep_tuc_mua" style="vertical-align:middle;"/></a>
				<?php if($count <= 0){ ?>
				<a href="<?php echo base_url().'index.php/payment/null_cart' ?>"><img src="<?php echo base_url().'images/thanhtoan.gif' ?>" alt="thanh toan" style="vertical-align:middle" /></a>
				<?php } 
					else if(isset($_SESSION['session_customer_full_name'])) { 
					
				?>
				<a href="<?php echo base_url().'order_complete' ?>"><img src="<?php echo base_url().'images/thanhtoan.gif' ?>" alt="thanh toan" style="vertical-align:middle;"/></a>					
				<?php } else { ?>	
				<a href="<?php echo base_url().'payment' ?>"><img src="<?php echo base_url().'images/thanhtoan.gif' ?>" alt="thanh toan" style="vertical-align:middle;"/></a>		
				<?php } ?>
			</div>
		</form>
		<script type="text/javascript">
			function update_cart()
			{
				document.forms["frmCart"].submit();
			}
		</script>
		</div>
	</div>
</div>
<?php 
	$this->load->view('part_view/mod_home_slide_bottom'); 
	$this->load->view('part_view/mod_footer_content');  
	$this->load->view('footer');
?>

